<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('项目表新增')"/>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
											
							<div class="layui-form-item">
			                    <label class="layui-form-label">项目名称</label>
			                    <div class="layui-input-block">
			                        <input type="text" name="projectName" autocomplete="off" placeholder="项目名称" class="layui-input">
			                    </div>
			                </div>
											
			              	<div class="layui-form-item layui-hide">
			                    <label class="layui-form-label">首页图片</label>
			                    <div class="layui-input-block">
			                        <input type="text" name="indexImage" id="indexImage" autocomplete="off" placeholder="首页图片" class="layui-input">
			                    </div>
			                </div>
			                
			                <div class="layui-form-item">
			                    <label class="layui-form-label">首页图片</label>
			                    <div class="layui-input-block">
			                        <div class="layui-upload-drag" id="indexImage_ImgUpload">
			                          <i class="layui-icon"></i>
			                          <p>点击上传，或将文件拖拽到此处</p>
			                          <div class="layui-hide" id="indexImage_ImgUpload_View">
			                            <hr>
			                            <img src="" alt="上传成功后渲染" style="max-width: 196px">
			                          </div>
			                        </div>
			                    </div>
			                </div>     
									
											
							<div class="layui-form-item">
			                    <label class="layui-form-label">项目介绍</label>
			                    <div class="layui-input-block">
			                        <input type="text" name="remarks" autocomplete="off" placeholder="项目介绍" class="layui-input">
			                    </div>
			                </div>
									
		
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="goviewProject-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form','laydate','upload','jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath+"/GoviewProjectController";

		let FILE_PATH = rootPath+"/oss";
        let upload = layui.upload;
        let BucketName='[[${BucketName}]]';
		var laydate = layui.laydate;
        //同时绑定多个
        lay('.datetime-input').each(function(){
          laydate.render({
            elem: this
            ,trigger: 'click'
            ,type: 'datetime'
          });
        });

																																										
				//拖拽上传 文档：https://www.layui.com/doc/modules/upload.html
				upload.render({
					elem: '#indexImage_ImgUpload'
					,url: FILE_PATH+"/object/"+BucketName //改成您自己的上传接口
					,field: 'object' //设定文件域的字段名
					,done: function(result){
						console.log(result);
						if (result.code==200) {
							layer.msg('上传成功');
							layui.$('#indexImage_ImgUpload_View').removeClass('layui-hide').find('img').attr('src', result.data.objectContent.httpRequest.uri);
							if(result.data.key!=null){
								$("#indexImage").val(result.data.key);
							}
						} else {
							layer.msg(result.msg, {icon: 2, time: 1000});
						}
					}
				});


												
        //保存
        form.on('submit(goviewProject-save)', function (data) {
        	let loader = layer.load();
            $.ajax({
                url: MODULE_PATH+'/add',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("goviewProject-table");
                            layer.close(loader);
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                        layer.close(loader);
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>